package com.googlecode.stemwijzer.shared.model;

import java.util.HashMap;

import com.googlecode.stemwijzer.shared.model.constants.Answer;
import com.googlecode.stemwijzer.shared.model.constants.Question;

public class Questionnaire extends DomainObject {

	private HashMap<Question, Answer> data;
	private String name;

	public Questionnaire() {

	}

	public Questionnaire(final String name) {
		this.name = name;
		this.data = new HashMap<Question, Answer>();
	}

	public Questionnaire(final String name,
			final HashMap<Question, Answer> questionnaire) {
		this.name = name;
		this.data = questionnaire;
	}

	public String getName() {
		return name;
	}

	public void setAnswer(final Question question, final Answer answer) {
		data.put(question, answer);
		System.out.println("Vraag [" + question.toString() + "], antwoord ["
				+ answer.toString() + "]");
	}

	public Answer getAnswer(final Question question) {
		if (question == null) {
			return null;
		}
		return data.get(question);
	}

	public Integer getDifference(final Questionnaire other) {
		Integer result = 0;

		for (Question q : Question.values()) {
			Answer a1 = data.get(q);
			Answer a2 = other.getAnswer(q);

			if (a1 != null && a2 != null) {
				result += Math.abs(a1.getValue() - a2.getValue());
			}
		}
		return result;
	}
}
